#!/bin/bash
# $Id$
#
# Description: Mutt Firefox helper script 
#
# Copyright (C) 2003,2004,2005,2006 Charles Mauch <cmauch@gmail.com>
#
# Verbatim copying, distribution, and display of this program is permitted in
# any medium, provided this notice is preserved.  Alternatively, you may create
# derivative works of any sort for any purpose, provided your versions contain
# no attribution to me, and that you assert your own authorship (and not mine)
# in every practical medium.

# open the URL "about:config" in Firefox. In there I right clicked and
# created a new string called "network.protocol-handler.app.mailto" with a
# value of the path to where you put this script

MAILTO_URL="$@"

#Strip off the protocol
MAIL_DATA=$(echo "$MAILTO_URL" | /bin/sed -s 's/^mailto://I')

#Get Recipient and strip it off
RECIPIENT=$(echo "$MAIL_DATA" | cut -d? -f1 -)
MAIL_DATA=$(echo "$MAIL_DATA" | /bin/sed -s "s/^$RECIPIENT//")

#Get Subject,BCC, and CC
SUBJECT=$(echo "$MAIL_DATA" | \
/bin/sed -s 's/.*?subject=//I' | /bin/sed -s 's/?.*//')
BCC=$(echo "$MAIL_DATA" | /bin/sed -s 's/.*?bcc=//I' | \
/bin/sed -s 's/?.*//')
CC=$(echo "$MAIL_DATA" | /bin/sed -s 's/.*?cc=//I' | \
/bin/sed -s 's/?.*//')

#Call mutt in an aterm
gnome-terminal -x muttng "$RECIPIENT" -b "$BCC" -c "$CC" -s "$SUBJECT"
